package com.moinut.studentattendancemanager.model.dao.proxy;

import com.moinut.studentattendancemanager.model.dao.IStudentDAO;
import com.moinut.studentattendancemanager.model.dao.impl.StudentDAOImpl;
import com.moinut.studentattendancemanager.model.vo.db.Student;

import java.util.List;

/**
 * @author MOILING
 */
public class StudentDAOProxy extends BaseDAOProxy<StudentDAOImpl> implements IStudentDAO {

    @Override
    public Student findLogin(Student student) throws Exception {
        Student getStudent = this.dao.findLogin(student);
        this.databaseConnection.close();
        return getStudent;
    }

    @Override
    public Student getStudentById(String studentId) throws Exception {
        Student student = this.dao.getStudentById(studentId);
        this.databaseConnection.close();
        return student;
    }

    @Override
    public List<Student> getStudentsByName(String studentName) throws Exception {
        List<Student> students = this.dao.getStudentsByName(studentName);
        this.databaseConnection.close();
        return students;
    }

    @Override
    public List<Student> getStudentsByClass(String classId) throws Exception {
        List<Student> students = this.dao.getStudentsByClass(classId);
        this.databaseConnection.close();
        return students;
    }

    @Override
    public List<Student> getStudentsByMajor(String major) throws Exception {
        List<Student> students = this.dao.getStudentsByMajor(major);
        this.databaseConnection.close();
        return students;
    }

    @Override
    public List<Student> getAllStudents() throws Exception {
        List<Student> students = this.dao.getAllStudents();
        this.databaseConnection.close();
        return students;
    }

    @Override
    public boolean updateStudentInfo(String oldId, Student newStudent) throws Exception {
        boolean flag = this.dao.updateStudentInfo(oldId, newStudent);
        this.databaseConnection.close();
        return flag;
    }

    @Override
    public boolean updateStudentPassword(String oldId, String newPassword) throws Exception {
        boolean flag = this.dao.updateStudentPassword(oldId, newPassword);
        this.databaseConnection.close();
        return flag;
    }

    @Override
    public boolean updateStudentEmail(String studentId, String newEmail) throws Exception {
        boolean flag = this.dao.updateStudentEmail(studentId, newEmail);
        this.databaseConnection.close();
        return flag;
    }

    @Override
    StudentDAOImpl setDAOImpl() {
        return new StudentDAOImpl(this.databaseConnection.getConnection());
    }
}
